package ar.uba.fi.crypto;

public class InternetAddressToByteConverter {

	public static byte[] MACAddressTo16ByteArray(String s) {
		
		s = s.replace(":", "");	
		s = s.replace("-", "");
		
		int addrLength = s.length() / 2;
		byte[] bts = new byte[16];
		for (int i = 0; i < addrLength; i++) {
			bts[i] = (byte) Integer.parseInt(s.substring(2*i, 2*i+2), 16);
		}
		
		// padding (la dir. tiene que tener 16 bytes)
		for(int i = addrLength; i < 16; i++) {
			bts[i] = 0x00;
		}
		
		return bts;
	}
	
	public static byte[] IPAddressToByteArray(String s) {
		String[] octets = s.split("\\.");
		byte[] bts = new byte[octets.length];
		for(int i = 0; i < bts.length; i++) {
			bts[i] = (byte)(int)Integer.valueOf(octets[i]);
		}
		return bts;
	}
}